#!/usr/bin/php -q
<?php


	include("/root/config.php");

	$handle=opendir("/var/lib/vz/template/cache"); 
	while ($datei = readdir ($handle)) { 
		if($datei != "images.php") {
			unlink($datei);
		}
	} 
	closedir($handle);

	$file = file_get_contents("http://serveradminpanel.square7.ch/updatefiles/openvz-images.xml");
	$datei = fopen("filename.xml","w+");
	fwrite($datei, $file);
	fclose($datei);
	$xml = simplexml_load_file("filename.xml"); 
        	foreach($xml->image as $image) { 
		
		$command = system("wget $image->file");
		$command = system("mv /root/$image->name /var/lib/vz/template/cache/");
}

	
	$handle=opendir("/var/lib/vz/template/cache"); 
	while ($datei = readdir ($handle)) { 
		if($datei == "images.php" OR $datei == ".." OR $datei == "." OR $datei == "filename.xml") {
			//NICHTS
		} else {
			mysql_query("INSERT INTO vserver_images SET image = '".$datei."', node = '".$node."'");
		}
	} 
	closedir($handle);



?>